package com.example.enterprise.controller;






import com.example.enterprise.entity.FileInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.PostConstruct;
import java.io.*;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : ramostear
 * @date : 2019/3/8 0008-15:35
 */




@Controller
public class FileController {

//
//    @Value ( "${picture.upload.root.dir}" )
//    String fileUploadRootDir;
//
//
//    private static Map<String, FileInfo> fileRepository = new HashMap<>();
//
//    @PostConstruct
//    public void initFileRepository(){
//        FileInfo file1 = new FileInfo ().setFileName ( "bg1.jpg" );
//        FileInfo file2 = new FileInfo ().setFileName ( "bg2.jpg" );
//        FileInfo file3 = new FileInfo ().setFileName ( "bg3.jpg" );
//        fileRepository.put ( file1.getName (),file1 );
//        fileRepository.put ( file2.getName (),file2 );
//        fileRepository.put ( file3.getName (),file3 );
//    }
//
//    @PostMapping(value = "/upload",consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
//    @ResponseBody
//    public String fileUpload(@RequestParam("file") MultipartFile file) throws IOException {
//
//        File convertFile = new File ( fileUploadRootDir+file.getOriginalFilename ());
//        FileOutputStream fileOutputStream = new FileOutputStream ( convertFile );
//        fileOutputStream.write ( file.getBytes () );
//        fileOutputStream.close ();
//
//        FileInfo fileInfo = new FileInfo()
//                .setFileName ( file.getOriginalFilename());
//
//        fileRepository.put ( fileInfo.getName (),fileInfo);
//
//        return "File is upload successfully";
//    }
}
